package edu.hawaii.teams.halealohacli.command;

import static org.junit.Assert.assertTrue;
import org.wattdepot.client.WattDepotClient;
import org.junit.Test;
import edu.hawaii.teams.halealohacli.processor.Processor;

/**
 * Test cases to test functionality of MonitorGoal class.
 * 
 * Note that no error message would show for a monitor-goal
 * call that only contains the tower or lounge because
 * the Main class, from the base code, needs fixing.
 * Therefore, that sort of command is not tested here.
 * 
 * @author Marifel Barbasa
 *
 */
public class TestMonitorGoal {
  
  /**
   * Performs testing to ensure MonitorGoal class is running properly.
   * 
   * @throws Exception - error.
   */
  @Test
  public void testMonitorGoal() throws Exception {
    
    // For connecting to the server and the MonitorGoal class
    WattDepotClient client = new WattDepotClient("http://server.wattdepot.org:8190/wattdepot/");
    Processor pro = new Processor(client);
    String command0 = "monitor-goal Lehua 5 5";
    String command1 = "monitor-goal Lehua 4 k";
    String command2 = "monitor-goal Lehua k 3";
    String command3 = "monitor-goal Lehua 0 1";
    String command4 = "monitor-goal Lehua 100 1";
    String command5 = "monitor-goal there is one extra";
    String command6 = "monitor-goal one short";
    
    // Error messages to compare against
    String callFirst = "Error: The set-baseline command must first be " +
        "called on the specified source.";
    String boundaries = "Error: The goal must be between 1 and 99 (inclusive), " +
        "and the interval must be greater than 0.";
    String bothIntegers = "Error: Both the goal and interval must be integers.";
    String commandFormat = "Error: Format for this command should be monitor-goal " +
        "[tower | lounge] [goal] [interval]";
    
    // Test valid input without calling set-baseline first
    pro.parseMonitorGoal(command0);
    assertTrue("Testing if an error is thrown if set-baseline is not called first",
        pro.getMonitorGoalOutput().equals(callFirst));
   
    pro.parseSetBaseLine("set-baseline Lehua");
    
    // Test invalid input
    pro.parseMonitorGoal(command1);
    assertTrue("Testing for both integers",
        pro.getMonitorGoalOutput().equals(bothIntegers));
    
    pro.parseMonitorGoal(command2);
    assertTrue("Testing for both integers",
        pro.getMonitorGoalOutput().equals(bothIntegers));
    
    pro.parseMonitorGoal(command3);
    assertTrue("Testing for boundaries",
        pro.getMonitorGoalOutput().equals(boundaries));
    
    pro.parseMonitorGoal(command4);
    assertTrue("Testing for boundaries",
        pro.getMonitorGoalOutput().equals(boundaries));
    
    pro.parseMonitorGoal(command5);
    assertTrue("Testing for command format",
        pro.getMonitorGoalOutput().equals(commandFormat));
    
    pro.parseMonitorGoal(command6);
    assertTrue("Testing for command format",
        pro.getMonitorGoalOutput().equals(commandFormat));
  }

}
